<template>
    <div class="zt-dialog-solt-2">
        <div class="zt-dialog-solt">
            <compass v-if="antenna" :angle="antenna.antennaAngle" @upAngle="upAngle"></compass>
            <div class="antenna-status" v-if="antenna">
                <span>当前状态：</span>
                <span style="color:#74C8CE ;" v-if="antenna.status == '0'">正常</span>
                <span style="color:red ;" v-if="antenna.status == '1'">异常</span>
            </div>
            <div class="flex" style="margin-top: 20px;">
                <el-button class="bt-blue " @click="antennaStart" style="margin-left: 140px; ">转动</el-button>
                <el-button class="bt-yellow " @click="antennaStop" style="margin-left: 20px; ">停止</el-button>
            </div>
        </div>

    </div>
</template>

<script>
import { listAntenna, getAntenna, delAntenna, addAntenna, updateAntenna, postAntennaZero, postAntennaStop, postAntennaStart } from "@/api/business/antenna";
import Compass from "@/components/TZ/Compass"
export default {
    name: 'swAntenna',
    components: { Compass },
    props: {
        // 天线控制数据
        antennaId: {},
    },
    watch: {
    },
    data() {
        return {
            // 天线数据
            antenna: null,
        }
    },
    created() {
        this.handleAntennaScope();
    },
    methods: {
        // 打开天线详情
        handleAntennaScope() {
            getAntenna(this.antennaId).then(response => {
                const result = response.data;
                this.antenna = {
                    antennaeId: result.antennaeId,
                    antennaAngle: Number(result.antennaAngle),
                    status: result.status
                }
                if(this.antenna.status == '1') {
                    this.$message.warning("天线故障");
                    return;
                }
            });
        },
        upAngle(val) {
            this.antenna.antennaAngle = Number(val)
        },
        //天线转动
        antennaStart() {
            if(this.antenna.status == '1') {
                this.$message.warning("天线故障");
                return;
            }
            postAntennaStart({ angle: this.antenna.antennaAngle }).then(rs => {
                if(rs.code == 200){
                    this.$message.success(rs.msg);
                }else{
                    this.$message.error(rs.msg);
                }
            }).catch(er=>{
                this.$message.error(rs.msg);
            });
        },
        //天线停止
        antennaStop() {
            if(this.antenna.status == '1') {
                this.$message.warning("天线故障");
                return;
            }
            postAntennaStop({}).then(rs => {
                if(rs.code == 200){
                    this.$message.success(rs.msg);
                }else{
                    this.$message.error(rs.msg);
                }
            }).catch(er=>{
                this.$message.error(rs.msg);
            });
        },
    }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.antenna-status {
    background: #394760;
    width: 360px;
    height: 40px;
    margin-top: 1px;
    text-align: center;
    line-height: 40px;
    color: #EDEDED;
    font-size: 18px;
}
</style>